package com.example.finaltool.mapper;

import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Update;

/**
 * @author dengbw
 * @date 2021/8/16 10:29 上午
 */
@Mapper
public interface SysUserMapper {

    @Update("UPDATE sys_user ssu,(SELECT su.user_id AS uId, GROUP_CONCAT( cfc.id ORDER BY cfc.sort_no asc) AS funId " +
            "FROM sys_user su, cmm_function_cofig cfc " +
            "WHERE su.sub_tenant_id = cfc.sub_tenant_id " +
            "and su.sub_tenant_id = #{subId} " +
            "AND cfc.user_type = 3 AND cfc.is_mr = 1 GROUP BY su.user_id ) temp SET ssu.nh_function = temp.funId WHERE ssu.user_id = temp.uId")
    int updateNonghu(Long subId);

    @Update("UPDATE sys_user ssu,( SELECT su.user_id AS uId, GROUP_CONCAT( cfc.id ORDER BY cfc.sort_no asc) AS funId " +
            "FROM sys_user su, cmm_function_cofig cfc " +
            "WHERE su.sub_tenant_id = cfc.sub_tenant_id " +
            "and su.sub_tenant_id = #{subId} " +
            "AND cfc.user_type = 2 AND cfc.is_mr = 1 GROUP BY su.user_id ) temp SET ssu.gb_function = temp.funId WHERE ssu.user_id = temp.uId;")
    int updateFuwu(Long subId);

    @Update("UPDATE sys_user_role sur, sys_user su SET sur.tenant_id = su.ding_corp_id, sur.sub_tenant_id = su.sub_tenant_id WHERE su.user_id = sur.user_id AND sur.tenant_id IS NULL AND su.ding_corp_id = #{corpId}")
    int fixMenu(String corpId);
}
